package com.hedd.shop.service.impl;

import com.hedd.shop.mapper.ProductMapper;
import com.hedd.shop.pojo.entity.Product;
import com.hedd.shop.pojo.qo.AccurateSearchQO;
import com.hedd.shop.pojo.qo.ProductInsertQO;
import com.hedd.shop.pojo.qo.ProductPagingQO;
import com.hedd.shop.service.ProductService;
import com.hedd.shop.utils.ProductPageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ludi
 * @date:2020/8/29 15:33
 * @description:商品业务
 */
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public List<Product> selectProductByTypeName(String TypeName) {
        return productMapper.selectProductByTypeName(TypeName);
    }

    @Override
    public Product selectProductById(Integer productId) {
        return productMapper.selectProductById(productId);
    }

    @Override
    public List<Product> selectProductOnSearch(String keyWords) {
        String appendKeyWord = "%"+keyWords+"%";
        return productMapper.selectProductOnSearch(appendKeyWord);
    }

    @Override
    public List<Product> selectProductOnAccurateSearch(AccurateSearchQO accurateSearchQO) {
        return productMapper.selectProductOnAccurateSearch(accurateSearchQO);
    }

    @Override
    public List<Product> selectProductUsingPaging(ProductPagingQO productPagingQO) {
        Integer count = productMapper.selectProductCountByTypeName(productPagingQO.getTypeName());
        ProductPageUtil productPageUtil = new ProductPageUtil(productPagingQO.getCurPage(),productPagingQO.getPageNum(),count);
        return productMapper.selectProductUsingPaging(productPageUtil.getOffset(),productPagingQO.getPageNum(),productPagingQO.getTypeName());
    }

    @Override
    public Integer selectProductCountByTypeName(String typeName) {
        return productMapper.selectProductCountByTypeName(typeName);
    }

    @Override
    public Integer insertProductCollection(ProductInsertQO productInsertQO) {
        return productMapper.insertProductCollection(productInsertQO);
    }

}
